﻿using STHPMS1.DAL.D_Core;
using STHPMS1.ICore.I_DAL.Repository;
using ServiceStack.OrmLite;
using System.Collections.Generic;
using STHPMS1.ICore.I_Entity.Stmpms1;
using System.Data;

namespace STHPMS1.DAL.D_Repository
{
    public class Dm_TrafaxleRepository : DalBase, IDm_TrafaxleRepository
    {

        public IEnumerable<IDm_Esalage> GetEsalageByModel<T>(string modelgroup_id)
             where T : class, IDm_Esalage
        {
            string sql = string.Format(@"
SELECT c.* from DM_ESALAGE c where c.segid in(
select a.segid from  
(  
  SELECT t.*,ROW_NUMBER() over (partition by t.SEGID order by t.PERFYEAR desc) num  
  FROM DM_HISTPERF t  
) a  
where num=1 and modelgroup_id='{0}' )  ;", modelgroup_id);


            IDbConnection conn = Adapter.OpenDbConnection();
            return conn.Select<T>(sql);
        }
    }
}
